package com.miao.hong.fang.webservice;

import java.util.ArrayList;
import java.util.List;

import javax.xml.namespace.QName;

import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.axis2.transport.http.HttpTransportProperties;
import org.apache.axis2.transport.http.HttpTransportProperties.Authenticator;

public class WebServiceTest {

	public static void main(String[] args) throws Exception {
//		System.setProperty("javax.net.ssl.trustStore", "D:\\Tomcat_7.0.37_qiyexuexi\\conf\\truststore");
//		System.setProperty("javax.net.ssl.trustStorePassword","password");
//		
//		RPCServiceClient serviceClient = new RPCServiceClient();
//		Options options = serviceClient.getOptions();
//		
//		EndpointReference targetEPR = new EndpointReference("https://localhost:8443/qiyexuexi/services/course");
//		options.setTo(targetEPR);
//		
//		Object[] entryArgs = new Object[] {};
//		
//		Class[] classes = new Class[] { String.class };
//		
//		QName opName = new QName("http://webservice.fang.hong.miao.com", "getCourseName");
//		
//		Object result = serviceClient.invokeBlocking(opName, entryArgs, classes)[0];
//		
//		System.out.println(result);
//		System.out.println(123);
		
		
		RPCServiceClient serviceClient = new RPCServiceClient();
		Options options = serviceClient.getOptions();
		EndpointReference targetEPR = new EndpointReference("http://localhost:8080/qiyexuexi/services/course");
		options.setTo(targetEPR);
		
//		Authenticator auth = new Authenticator();
//		auth.setUsername("abcde");
//		auth.setPreemptiveAuthentication(true);
//		auth.setPassword("1111");
//		options.setProperty(HTTPConstants.AUTHENTICATE, auth);
		
		//set weather
		QName opName = new QName("http://webservice.fang.hong.miao.com", "setWeather");
		Weather_pojo weather = new Weather_pojo();
		weather.setRain(true);
		weather.setTemperature(100);
		weather.setForecast("good");
		weather.setHowMuchRain(45.32f);
		List<String> historys = new ArrayList<String>();
		historys.add("yesterday");
		historys.add("eddddd");
		weather.setHistorys(historys);
		Object[] opSetWeatherArgs = new Object[]{weather, "today"};
		serviceClient.invokeRobust(opName, opSetWeatherArgs);
		
		//get weather
//		QName opName1 = new QName("http://webservice.fang.hong.miao.com", "getWeather");
//		Object[] opGetWeatherArgs = new Object[]{};
//		Class[] returnTypes = new Class[]{Weather_pojo.class};
//		Object[] response = serviceClient.invokeBlocking(opName1, opGetWeatherArgs, returnTypes);
//		Weather_pojo result = (Weather_pojo)response[0];
//		System.out.println(result.getTemperature());
		
	}
}
